home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / GoldHead.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  10.3 KB  |  364 lines

  1. class classes.enemy.GoldHead
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var clip;
  7.    var colorR;
  8.    var trans;
  9.    var colorTrans;
  10.    var f2;
  11.    var dir;
  12.    var axis;
  13.    var xDest;
  14.    var yDest;
  15.    var ep;
  16.    var oldDir;
  17.    var xMov = 0;
  18.    var yMov = 0;
  19.    var xMovT = 0;
  20.    var yMovT = 0;
  21.    var speedOrig = 10;
  22.    var speed = 10;
  23.    var xDestMet = false;
  24.    var yDestMet = false;
  25.    var c = 0;
  26.    var pUp = false;
  27.    var life = 10;
  28.    var nc = 0;
  29.    var xA = 0;
  30.    var yA = 0;
  31.    var nudging = false;
  32.    var hc = 0;
  33.    var power = 35;
  34.    var flashing = false;
  35.    var flashC = 0;
  36.    var Name = "goldHead";
  37.    function GoldHead(px, py, pmoveScript)
  38.    {
  39.       this.x = px;
  40.       this.y = py;
  41.       this.moveScript = pmoveScript.slice();
  42.       _root.d = _root.d + 1;
  43.       this.clip = _root.attachMovie("goldHead","goldHeadClip",_root.d + 50000);
  44.       this.clip._x = this.x;
  45.       this.clip._y = this.y;
  46.       this.speedVar();
  47.       this.colorR = _root.randRange(-10,10);
  48.       this.trans = new flash.geom.Transform(this.clip);
  49.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  50.       this.trans.colorTransform = this.colorTrans;
  51.       this.parseMoveScript();
  52.       if(_root.flashing)
  53.       {
  54.          this.flashing = true;
  55.          _root.flashing = false;
  56.       }
  57.       _root.stats.created = _root.stats.created + 1;
  58.    }
  59.    function nudge(pxA, pyA, pscale)
  60.    {
  61.       this.nc = 0;
  62.       this.nudging = true;
  63.       var _loc2_ = pscale / 100;
  64.       this.xA = pxA * _loc2_;
  65.       this.yA = pyA * _loc2_;
  66.    }
  67.    function speedVar()
  68.    {
  69.       if(random(3) == 1)
  70.       {
  71.          this.speed *= _root.randRange2(0.9998,1.0002);
  72.       }
  73.    }
  74.    function bombed(num)
  75.    {
  76.       this.f2 = "death";
  77.    }
  78.    function parseMoveScript()
  79.    {
  80.       this.dir = this.moveScript[0];
  81.       if(this.dir == "break")
  82.       {
  83.          delete this.moveScript;
  84.          this[this.axis + "MovT"] = 0;
  85.          this.f2 = "wander";
  86.          this.dir = _root.getDir(this.x,this.y);
  87.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  88.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  89.          this.speedVar();
  90.       }
  91.       else
  92.       {
  93.          this[this.axis + "MovT"] = 0;
  94.          this.f2 = "gotoXYDest";
  95.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  96.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  97.          this.speedVar();
  98.          if(this.dir == "L" || this.dir == "U")
  99.          {
  100.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  101.          }
  102.          else
  103.          {
  104.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  105.          }
  106.          this.moveScript.splice(0,2);
  107.       }
  108.    }
  109.    function gotoXYDest()
  110.    {
  111.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  112.       {
  113.          if(this.axis == "x")
  114.          {
  115.             this.x = this.xDest;
  116.          }
  117.          else
  118.          {
  119.             this.y = this.yDest;
  120.          }
  121.          this.parseMoveScript();
  122.       }
  123.    }
  124.    function getDirString()
  125.    {
  126.       if(this.xMovT < -1)
  127.       {
  128.          this.dir = "L";
  129.       }
  130.       else if(this.xMovT > 1)
  131.       {
  132.          this.dir = "R";
  133.       }
  134.       else if(this.yMovT > 1)
  135.       {
  136.          this.dir = "D";
  137.       }
  138.       else if(this.yMovT < -1)
  139.       {
  140.          this.dir = "U";
  141.       }
  142.    }
  143.    function wander()
  144.    {
  145.       if(random(100) > 96)
  146.       {
  147.          if(random(20) > 18)
  148.          {
  149.             this[this.axis + "MovT"] = 0;
  150.             this.f2 = "wait";
  151.             this.c = 0;
  152.             this.ep = _root.randRange(5,15);
  153.          }
  154.          else
  155.          {
  156.             this[this.axis + "MovT"] = 0;
  157.             this.axis = random(10) <= 4 ? "y" : "x";
  158.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  159.             this.getDirString();
  160.          }
  161.       }
  162.    }
  163.    function wait()
  164.    {
  165.       this.c = this.c + 1;
  166.       if(this.c == this.ep)
  167.       {
  168.          this.f2 = "wander";
  169.          this.axis = random(10) <= 4 ? "y" : "x";
  170.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  171.          this.getDirString();
  172.       }
  173.       if(random(100) > 95)
  174.       {
  175.          var _loc2_ = ["L","R","F"];
  176.          this.dir = _loc2_[random(_loc2_.length)];
  177.       }
  178.    }
  179.    function attacking()
  180.    {
  181.    }
  182.    function death()
  183.    {
  184.       _root.stats.destroyed = _root.stats.destroyed + 1;
  185.       _root.stats.score += 50000;
  186.       var _loc3_ = 0;
  187.       var _loc4_ = random(2) + 1;
  188.       while(_loc3_ < _loc4_)
  189.       {
  190.          _root.createPowerUp([this.x,this.y,"coin25"]);
  191.          _loc3_ = _loc3_ + 1;
  192.       }
  193.       _loc3_ = 0;
  194.       _loc4_ = random(5) + 5;
  195.       while(_loc3_ < _loc4_)
  196.       {
  197.          _root.createPowerUp([this.x,this.y,"coin10"]);
  198.          _loc3_ = _loc3_ + 1;
  199.       }
  200.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(60,80),_root.randRange(75,100),"Yellow"]);
  201.       _loc3_ = 0;
  202.       _loc4_ = random(3);
  203.       while(_loc3_ < _loc4_)
  204.       {
  205.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"goldHead","Red"]);
  206.          _loc3_ = _loc3_ + 1;
  207.       }
  208.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"yellow"]);
  209.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"yellow"]);
  210.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"yellow"]);
  211.       _root.audio.playLevel2("goldHeadX",_root.randRange(30,40));
  212.       _root.removeChar("goldHead");
  213.    }
  214.    function death2()
  215.    {
  216.       _root.removeChar("goldHead");
  217.    }
  218.    function main()
  219.    {
  220.       if(this.flashing)
  221.       {
  222.          this.flashC = this.flashC + 1;
  223.          var _loc8_ = 275 - this.flashC * 10;
  224.          this.colorTrans.greenOffset = _loc8_;
  225.          this.colorTrans.redOffset = _loc8_;
  226.          this.colorTrans.blueOffset = _loc8_;
  227.          this.trans.colorTransform = this.colorTrans;
  228.          if(this.flashC == 27)
  229.          {
  230.             this.colorTrans.greenOffset = 0;
  231.             this.colorTrans.redOffset = 0;
  232.             this.colorTrans.blueOffset = 0;
  233.             this.trans.colorTransform = this.colorTrans;
  234.             delete this.flashing;
  235.             delete this.flashC;
  236.          }
  237.       }
  238.       this[this.f2]();
  239.       if(this.oldDir != this.dir)
  240.       {
  241.          if(this.oldDir == undefined || this.dir == "F")
  242.          {
  243.             this.clip.body.eyes.gotoAndStop(this.dir);
  244.          }
  245.          else if(this.dir == "U" || this.dir == "D")
  246.          {
  247.             this.clip.body.eyes.gotoAndStop(this.oldDir);
  248.          }
  249.          else if(random(3) > 0)
  250.          {
  251.             if(this.dir == "R")
  252.             {
  253.                this.clip.body.eyes.gotoAndPlay("LtoR");
  254.             }
  255.             else
  256.             {
  257.                this.clip.body.eyes.gotoAndPlay("RtoL");
  258.             }
  259.          }
  260.          else
  261.          {
  262.             this.clip.body.eyes.gotoAndPlay("spin" + this.dir);
  263.          }
  264.       }
  265.       this.oldDir = this.dir;
  266.       if(this.nudging)
  267.       {
  268.          this.xA *= 0.5;
  269.          this.yA *= 0.5;
  270.          this.nc = this.nc + 1;
  271.          _loc8_ = 255 - this.nc * 17;
  272.          this.colorTrans.blueOffset = _loc8_;
  273.          this.colorTrans.greenOffset = _loc8_ / 2;
  274.          this.trans.colorTransform = this.colorTrans;
  275.          if(this.nc == 15)
  276.          {
  277.             this.xA = this.yA = 0;
  278.             this.nudging = false;
  279.             this.colorTrans.blueOffset = this.colorR;
  280.             this.colorTrans.greenOffset = this.colorR;
  281.             this.trans.colorTransform = this.colorTrans;
  282.          }
  283.       }
  284.       var _loc4_ = 0;
  285.       var _loc7_ = _root.broShots.length;
  286.       while(_loc4_ < _loc7_)
  287.       {
  288.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  289.          if(this.clip.hitTest(_root[_loc6_]))
  290.          {
  291.             var _loc3_ = _root.broShots[_loc4_];
  292.             var _loc5_ = this.life;
  293.             this.life -= _root[_loc3_].power;
  294.             if(this.life < 1)
  295.             {
  296.                this.f2 = "death";
  297.             }
  298.             else
  299.             {
  300.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  301.                _root.audio.playLevel4("goldHeadHit" + (random(2) + 1),_root.randRange(7,15));
  302.                this[this.axis + "MovT"] = 0;
  303.                this.axis = random(10) <= 4 ? "y" : "x";
  304.                this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  305.                this.getDirString();
  306.             }
  307.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  308.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  309.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  310.             _root[_loc3_].hit(_loc5_);
  311.             break;
  312.          }
  313.          _loc4_ = _loc4_ + 1;
  314.       }
  315.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  316.       {
  317.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  318.          this.f2 = "death";
  319.       }
  320.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  321.       {
  322.          this.f2 = "death2";
  323.       }
  324.       if(this.xMovT < this.xMov)
  325.       {
  326.          this.xMov -= 0.2;
  327.       }
  328.       else if(this.xMovT > this.xMov)
  329.       {
  330.          this.xMov += 0.2;
  331.       }
  332.       else
  333.       {
  334.          this.xMov = this.xMovT;
  335.       }
  336.       if(this.yMovT < this.yMov)
  337.       {
  338.          this.yMov -= 0.2;
  339.       }
  340.       else if(this.yMovT > this.yMov)
  341.       {
  342.          this.yMov += 0.2;
  343.       }
  344.       else
  345.       {
  346.          this.yMov = this.yMovT;
  347.       }
  348.       if(random(100) > 98)
  349.       {
  350.          this.clip.body.eyes.clip.gotoAndPlay("blink");
  351.       }
  352.       if(random(10) == 9)
  353.       {
  354.          _root.fxID = _root.fxID + 1;
  355.          _root["goldHeadFX" + _root.fxID] = new classes.fx.GoldHeadFX(this.x,this.y,_root.fxID);
  356.          _root.addFX("goldHeadFX" + _root.fxID);
  357.       }
  358.       this.x += this.xMov + this.xA;
  359.       this.y += this.yMov + this.yA + 0.5 * Math.sin(this.hc += 0.2);
  360.       this.clip._x = this.x;
  361.       this.clip._y = this.y;
  362.    }
  363. }
  364.